# -*- coding=utf-8 -*-

from flask import Flask
from exs import db
from config import configs
from models import User, Role
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager

app = Flask(__name__)

app.config.from_object(configs['DEV'])

db.init_app(app)
manager = Manager(app)
migrate = Migrate(app, db)

if __name__ == '__main__':
    with app.app_context():
        # db.create_all()
        # role = Role(role_name='管理员')
        # db.session.add(role)
        # db.session.commit()
        #
        # role = Role.query.filter_by(role_name='管理员').first()
        #
        # user = User(username='admin', password='123456', role_id=role.id)
        # db.session.add(user)
        # db.session.commit()
        # user = User(username='小明', password='123456', role_id=role.id)
        # db.session.add(user)
        # db.session.commit()
        # user = User(username='小红', password='qwer1234', role_id=role.id)
        # db.session.add(user)
        # db.session.commit()
        # user = User.query.filter_by(username='admin').first()
        # print(user)
        # role = Role.query.filter_by(role_name='管理员').first()
        # print(role.users)
        # for user in role.users:
        #     print(user.role)
        manager.add_command("db", MigrateCommand)
        manager.run()
